package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)
//事务
func main() {
	db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/email?charset=utf8")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer db.Close()
	var trans *sql.Tx
	trans, err = db.Begin()
	if err != nil {
		fmt.Println(err)
		return
	}
	_, err = trans.Exec("insert into sequence(id,`key`,current_value) value(?,?,?)", "1", "t", "1")
	if err != nil {
		trans.Rollback()
	} else {
		trans.Commit()
	}

}